package net.xdclass.service.impl;

import net.xdclass.manager.ProductManager;
import net.xdclass.model.ProductDO;
import net.xdclass.model.vo.ProductVO;
import net.xdclass.service.ProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小冯
 * @since 2023-07-18
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductManager productManager;

    @Override
    public List<ProductVO> list() {
        List<ProductDO> list = productManager.list();
        List<ProductVO> productVOList = list.stream().map(pro -> this.beanProcess(pro)).collect(Collectors.toList());
        return productVOList;
    }

    @Override
    public ProductVO detail(long productId) {
        ProductDO detail = productManager.detail(productId);
        return beanProcess(detail);
    }

    private ProductVO beanProcess(ProductDO productDO) {
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(productDO,productVO);
        return productVO;
    }

}
